<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Master_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert_ta($data){
		$this->db->insert('tb_master_tahun_ajaran',$data);
	}
	
	function get_tahunajaran(){
		$this->db->select('ta.*, s.NAMA_SEKOLAH ,ta.ISAKTIF as AKTIF, ta.KETERANGAN as KET, d.NAMA_DEPARTMENT');
		$this->db->from('tb_master_tahun_ajaran ta');
		$this->db->join('tb_department d','d.ID_DEPARTMENT=ta.DEPARTMENT'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=ta.ID_SEKOLAH'); 
		// $this->db->where("ta.ISAKTIF=1");
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('ta.*, s.NAMA_SEKOLAH, ta.ISAKTIF as aktif, ta.KETERANGAN as KET, d.NAMA_DEPARTMENT');
		$this->db->from('tb_master_tahun_ajaran ta');
		$this->db->join('tb_department d','d.ID_DEPARTMENT=ta.DEPARTMENT');
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=ta.ID_SEKOLAH');		
		// $this->db->where("ta.ISAKTIF=1");
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function delete_ta($thn_ajaran){
		$this->db->where('ID_TA', $thn_ajaran);
		$this->db->delete('tb_master_tahun_ajaran'); 
	}
	
	function get_taID($thn_ajaran){
		
		//Select table column
		$this->db->select('ta.*, ta.KETERANGAN as KET, ta.ISAKTIF as AKTIF, ta.ID_SEKOLAH as ID_SEK');
		$this->db->from('tb_master_tahun_ajaran ta');
		$this->db->join('tb_department d','d.ID_DEPARTMENT=ta.DEPARTMENT'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=ta.ID_SEKOLAH'); 
		$this->db->where('ID_TA',$thn_ajaran);
		$query = $this->db->get();
		return $query;
	}
	
	function get_semester_aktif(){
		$this->db->select('ID_SMT');
		$this->db->from('tb_master_semester');
		$this->db->where('ID_SEKOLAH',$this->session->userdata('unitid'));
		$this->db->where('ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}	
	
	function get_ta_aktif(){
		$this->db->select('ID_TA');
		$this->db->from('tb_master_tahun_ajaran');
		$this->db->where('ID_SEKOLAH',$this->session->userdata('unitid'));
		$this->db->where('ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	
	function update_ta($data,$thn_ajaran){
		$this->db->where('ID_TA',$thn_ajaran);
		$this->db->update('tb_master_tahun_ajaran',$data);
	}
	
	function update_isaktif($data,$value,$nameid,$table){ 
		$sql = "UPDATE $table SET ISAKTIF = 0 WHERE $nameid <> $value";
		$query = $this->db->query($sql);
		
		// $this->db->where($nameid .'<>',$value);
		// // $this->db->where('ID_SEKOLAH',$id_sekolah);
		// // $this->db->where('DEPARTMENT',$id_dep);
		// $this->db->update('TB_MASTER_TAHUN_AJARANs',$data);
	}
	
	function combo_ta(){
		$this->db->select('*');
		$this->db->from('tb_master_tahun_ajaran');
		// $this->db->where('ID_TA',$thn_ajaran);
		$query = $this->db->get();
		return $query;
	}
	
	function validasi_ta($dep, $ta){
		
		//Select table column
		$this->db->select('count(*) as jml, ID_TA');
		$this->db->from('tb_master_tahun_ajaran ');
		$this->db->where('TAHUN_AJARAN',$ta);
		$this->db->where('DEPARTMENT',$dep);
		$query = $this->db->get();
		return $query;
	}
	
	function getLastTa(){
		$this->db->select('max(ID_TA) as maxid');
		$this->db->from('tb_master_tahun_ajaran');
		$query = $this->db->get();
		return $query;
	}
	// ==============================================
	
	function get_tingkat(){
		
		//Select table column
		// $table_column = 'ID_TINGKAT,';
		// $table_column .= 'ta.TAHUN_AJARAN as TAHUN_AJARAN,';
		// $table_column .= 'TINGKAT,';
		// $table_column .= 'KETERANGAN,';
		
		$this->db->select('t.*,s.NAMA_SEKOLAH, d.NAMA_DEPARTMENT, t.ISAKTIF as AKTIF, t.KETERANGAN as KET');
		$this->db->from('tb_master_tingkat t'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=t.ID_SEKOLAH');
		$this->db->join('tb_department d','t.DEPARTMENT=d.ID_DEPARTMENT'); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('t.*, s.NAMA_SEKOLAH, d.NAMA_DEPARTMENT, t.ISAKTIF as AKTIF, t.KETERANGAN as KET');
		$this->db->from('tb_master_tingkat t'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=t.ID_SEKOLAH');
		$this->db->join('tb_department d','t.DEPARTMENT=d.ID_DEPARTMENT');
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	function insert_tingkat($data){
		$this->db->insert('tb_master_tingkat',$data);
	}
	function delete_tingkat($id_tingkat){
		$this->db->where('ID_TINGKAT', $id_tingkat);
		$this->db->delete('tb_master_tingkat'); 
	}
	
	function get_tingkatID($id_tingkat){
		
		//Select table column
		$this->db->select('t.*, t.KETERANGAN as KET, t.ISAKTIF as AKTIF, d.ID_DEPARTMENT, t.ID_SEKOLAH as ID_SEK');
		$this->db->from('tb_master_tingkat t');
		$this->db->join('tb_department d','t.DEPARTMENT=d.ID_DEPARTMENT'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=t.ID_SEKOLAH'); 
		$this->db->where('ID_TINGKAT',$id_tingkat);
		$query = $this->db->get();
		return $query;
	}
	
	function update_tingkat($data,$id_tingkat){
		$this->db->where('ID_TINGKAT',$id_tingkat);
		$this->db->update('tb_master_tingkat',$data);
	}
	
	function validasi_tingkat($dep, $tk){
		//Select table column
		$this->db->select('count(*) as jml, ID_TINGKAT');
		$this->db->from('tb_master_tingkat ');
		$this->db->where('TINGKAT',$tk);
		$this->db->where('DEPARTMENT',$dep);
		$query = $this->db->get();
		return $query;
	}
	
	function getLastTk(){
		$this->db->select('max(ID_TINGKAT) as maxid');
		$this->db->from('tb_master_tingkat');
		$query = $this->db->get();
		return $query;
	}
	//=============================================================
	
	function combo_dept(){
		$this->db->select('*');
		$this->db->from('tb_department');
		$this->db->where('ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	function combo_tingkat(){
		$this->db->select('*');
		$this->db->from('tb_master_tingkat');
		$this->db->where('ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	function combo_tahunajaran(){
		$this->db->select('*');
		$this->db->from('tb_master_tahun_ajaran');
		$this->db->where('ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	function combo_sekolah(){
		$this->db->select('*');
		$this->db->from('tb_master_sekolah');
		$this->db->where('ISAKTIF',1);
			$this->db->where("ID_SEKOLAH !=",'-1');
		$query = $this->db->get();
		return $query;
	}
	
	function combo_pegawai(){
		$this->db->select('*');
		$this->db->from('tb_pegawai');
		$this->db->where('ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	function combo_kondisi($key=''){
		$this->db->select('*');
		$this->db->from('tb_master_kondisi');
		if($key!='')
			$this->db->where('ID_KONDISI',$key);
		$query = $this->db->get();
		return $query;
	}
	function combo_bahasa($key=''){
		$this->db->select('*');
		$this->db->from('tb_master_bahasa');
		if($key!='')
			$this->db->where('ID_BAHASA',$key);
		$query = $this->db->get();
		return $query;
	}
	function combo_pendidikan($key=''){
		$this->db->select('*');
		$this->db->from('tb_master_rwtpendidikan');
		if($key!='')
			$this->db->where('ID_RWTPENDIDIKAN',$key);
		$query = $this->db->get();
		return $query;
	}
	function combo_pekerjaan($key=''){
		$this->db->select('*');
		$this->db->from('tb_master_pekerjaan');
		if($key!='')
			$this->db->where('ID_PEKERJAAN',$key);
		$query = $this->db->get();
		return $query;
	}
	function combo_agama($key=''){
		$this->db->select('*');
		$this->db->from('tb_master_agama');
		if($key!='')
			$this->db->where('ID_AGAMA',$key);
		$query = $this->db->get();
		return $query;
	}
	
	function combo_tahunajaran_kelas($id_sekolah){
		$this->db->select('*');
		$this->db->from('tb_master_sekolah'); 
		$this->db->where('ID_SEKOLAH',$id_sekolah);
		$query_sekolah = $this->db->get()->row();
		
		$this->db->select('ta.ID_TA,ta.TAHUN_AJARAN');
		$this->db->from('tb_master_sekolah s');
		$this->db->join('tb_master_tahun_ajaran ta','s.ID_SEKOLAH=ta.ID_SEKOLAH','left'); 
		$this->db->where('ta.ID_SEKOLAH',$id_sekolah);
		$this->db->where('ta.DEPARTMENT',$query_sekolah->ID_DEPARTMENT);
		$this->db->where('ta.ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	function combo_tingkat_kelas($id_sekolah){
		$this->db->select('*');
		$this->db->from('tb_master_sekolah'); 
		$this->db->where('ID_SEKOLAH',$id_sekolah);
		$query_sekolah = $this->db->get()->row();
	
		$this->db->select('t.ID_TINGKAT,t.TINGKAT');
		$this->db->from('tb_master_sekolah s');
		$this->db->join('tb_master_tingkat t','s.ID_SEKOLAH=t.ID_SEKOLAH','left'); 
		$this->db->join('tb_department d','d.ID_DEPARTMENT=t.DEPARTMENT','left'); 
		$this->db->where('t.ID_SEKOLAH',$id_sekolah);
		$this->db->where('t.DEPARTMENT',$query_sekolah->ID_DEPARTMENT);
		$this->db->where('t.ISAKTIF',1);
		$query = $this->db->get();
		return $query;
	}
	
	function combo_kelas($id_sekolah,$id_tahunajaran,$id_tingkat){
		$this->db->select('*');
		$this->db->from('tb_master_kelas');
		$this->db->where('ID_SEKOLAH',$id_sekolah);
		$this->db->where('ID_TAHUNAJARAN',$id_tahunajaran);
		$this->db->where('ID_TINGKAT',$id_tingkat);
		$this->db->where('ISAKTIF',1);
		$this->db->order_by('ID_KELAS');
		$query = $this->db->get();
		return $query;
	}	
	
	function combo_pelajaran($id_sekolah,$id_tahunajaran){
		$this->db->select('*');
		$this->db->from('tb_pelajaran');
		$this->db->where('ID_SEKOLAH',$id_sekolah);
		$this->db->where('TAHUN_AJARAN',$id_tahunajaran);
		// $this->db->where('ISAKTIF',1);
		// $this->db->order_by('ID_KELAS');
		$query = $this->db->get();
		return $query;
	}
	//=============================================================
	
	function get_semester(){
		
		$this->db->select('s.*, sek.NAMA_SEKOLAH, d.NAMA_DEPARTMENT, s.ISAKTIF as AKTIF, s.KETERANGAN as KET');
		$this->db->from('tb_master_semester s'); 
		$this->db->join('tb_department d','s.DEPARTMENT=d.ID_DEPARTMENT'); 
		$this->db->join('tb_master_sekolah sek','sek.ID_SEKOLAH=s.ID_SEKOLAH'); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('s.*, sek.NAMA_SEKOLAH, d.NAMA_DEPARTMENT, s.ISAKTIF as AKTIF, s.KETERANGAN as KET');
		$this->db->from('tb_master_semester s'); 
		$this->db->join('tb_department d','s.DEPARTMENT=d.ID_DEPARTMENT');
		$this->db->join('tb_master_sekolah sek','sek.ID_SEKOLAH=s.ID_SEKOLAH'); 
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	function insert_semester($data){
		$this->db->insert('tb_master_semester',$data);
	}
	function delete_semester($id_semester){
		$this->db->where('ID_SMT', $id_semester);
		$this->db->delete('tb_master_semester'); 
	}
	
	function get_semesterID($id_semester){
		
		//Select table column
		$this->db->select('s.*, s.KETERANGAN as KET, s.ISAKTIF as AKTIF, d.ID_DEPARTMENT, s.ID_SEKOLAH as ID_SEK');
		$this->db->from('tb_master_semester s');
		$this->db->join('tb_department d','s.DEPARTMENT=d.ID_DEPARTMENT'); 
		$this->db->join('tb_master_sekolah se','se.ID_SEKOLAH=s.ID_SEKOLAH'); 
		$this->db->where('ID_SMT',$id_semester);
		$query = $this->db->get();
		return $query;
	}
	
	function update_semester($data,$id_semester){
		$this->db->where('ID_SMT',$id_semester);
		$this->db->update('tb_master_semester',$data);
	}
	
	function validasi_semester($dep, $smt){
		
		//Select table column
		$this->db->select('count(*) as jml, ID_SMT');
		$this->db->from('tb_master_semester ');
		$this->db->where('SEMESTER',$smt);
		$this->db->where('DEPARTMENT',$dep);
		$query = $this->db->get();
		return $query;
	}
	
	function getLastSmt(){
		$this->db->select('max(ID_SMT) as maxid');
		$this->db->from('tb_master_semester');
		$query = $this->db->get();
		return $query;
	}
	//=============================================================
	
	function get_kelas($ta=''){
		
		$this->db->select('k.*, s.NAMA_SEKOLAH, ta.TAHUN_AJARAN, t.TINGKAT, k.ISAKTIF as AKTIF, k.KETERANGAN as KET, p.*');
		$this->db->from('tb_master_kelas k'); 
		$this->db->join('tb_master_tahun_ajaran ta','k.ID_TAHUNAJARAN=ta.ID_TA'); 
		$this->db->join('tb_master_tingkat t','t.ID_TINGKAT=k.ID_TINGKAT'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=k.ID_SEKOLAH');
		$this->db->join('tb_pegawai p','p.NIP=k.NIP_WALI');
		// if($ta!='')
			$this->db->where('k.ID_TAHUNAJARAN', $ta);
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('k.*, s.NAMA_SEKOLAH, ta.TAHUN_AJARAN, t.TINGKAT, k.ISAKTIF as AKTIF, k.KETERANGAN as KET, p.*');
		$this->db->from('tb_master_kelas k'); 
		$this->db->join('tb_master_tahun_ajaran ta','k.ID_TAHUNAJARAN=ta.ID_TA'); 
		$this->db->join('tb_master_tingkat t','t.ID_TINGKAT=k.ID_TINGKAT'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=k.ID_SEKOLAH');
		$this->db->join('tb_pegawai p','p.NIP=k.NIP_WALI');
		// if($ta!='')
			$this->db->where('k.ID_TAHUNAJARAN', $ta);
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	function insert_kelas($data){
		$this->db->insert('tb_master_kelas',$data);
	}
	function delete_kelas($id_kelas){
		$this->db->where('ID_KELAS', $id_kelas);
		$this->db->delete('tb_master_kelas'); 
	}
	
	function get_kelasID($id_kelas){
		
		//Select table column
		$this->db->select('k.*, s.NAMA_SEKOLAH, ta.TAHUN_AJARAN, t.TINGKAT, k.ISAKTIF as AKTIF, k.KETERANGAN as KET, k.ID_SEKOLAH as ID_SEK');
		$this->db->from('tb_master_kelas k'); 
		$this->db->join('tb_master_tahun_ajaran ta','k.ID_TAHUNAJARAN=ta.ID_TA'); 
		$this->db->join('tb_master_tingkat t','t.ID_TINGKAT=k.ID_TINGKAT'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=k.ID_SEKOLAH'); 
		$this->db->where('ID_KELAS',$id_kelas);
		$query = $this->db->get();
		return $query;
	}
	
	function update_kelas($data,$id_kelas){
		$this->db->where('ID_KELAS',$id_kelas);
		$this->db->update('tb_master_kelas',$data);
	}
	
	function validasi_kelas($tk, $kelas, $ta){
		
		//Select table column
		$this->db->select('count(*) as jml, ID_KELAS');
		$this->db->from('tb_master_kelas');
		$this->db->where('ID_TAHUNAJARAN',$ta);
		$this->db->where('ID_TINGKAT',$tk);
		$this->db->where('KELAS',$kelas);
		$query = $this->db->get();
		return $query;
	}
	
	function getLastKelas(){
		$this->db->select('max(ID_KELAS) as maxid');
		$this->db->from('tb_master_kelas');
		$query = $this->db->get();
		return $query;
	}
	
	//=============================================================
	
	function getall_unit_org(){
		$this->db->select('*');
		$this->db->from('tb_master_sekolah');
		$this->db->where("ISAKTIF > 0");
		$this->db->where("ID_SEKOLAH !=",'-1');
		$query = $this->db->get();
		return $query;
	}
	
	function get_namasekolah(){
		
		$this->db->select('*');
		$this->db->from('tb_master_sekolah');
		//$this->db->where("ISAKTIF > 0");
		if($this->session->userdata('roleid')!='0'){
			$this->db->where("ID_SEKOLAH !=",'-1');
		}
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('tb_master_sekolah'); 
		//$this->db->where("ISAKTIF > 0");
		if($this->session->userdata('roleid')!='0'){
			$this->db->where("ID_SEKOLAH !=",'-1');
		}
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function insert_namasekolah($data){
		$query = $this->db->insert('tb_master_sekolah',$data);
		return $query;
	}
	
	function get_last_id(){
		$this->db->select('*');
		$this->db->from('tb_master_sekolah'); 
		$query = $this->db->get();
		return $query;
	}
	
	function get_namasekolahID($id_namasekolah){
		
		//Select table column
		$this->db->select('*');
		$this->db->from('tb_master_sekolah'); 
		$this->db->where('ID_SEKOLAH',$id_namasekolah);
		$query = $this->db->get();
		return $query;
	}
	
	function update_namasekolah($data,$id_namasekolah){
		$this->db->where('ID_SEKOLAH',$id_namasekolah);
		$this->db->update('tb_master_sekolah',$data);
	}
	
	function delete_namasekolah($id_sekolah){
		$this->db->where('ID_SEKOLAH', $id_sekolah);
		$this->db->delete('tb_master_sekolah'); 
	}
	
	//==================================================================
	function get_department(){
		
		$this->db->select('d.*, s.NAMA_SEKOLAH, p.*');
		$this->db->from('tb_department d'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=d.ID_SEKOLAH');
		$this->db->join('tb_pegawai p','p.NIP=d.NIPKEPSEK');
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('d.*,s.NAMA_SEKOLAH, p.*');
		$this->db->from('tb_department d'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=d.ID_SEKOLAH');
		$this->db->join('tb_pegawai p','p.NIP=d.NIPKEPSEK');
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function insert_department($data){
		$this->db->insert('tb_department',$data);
	}
	
	function get_depID($id_dep){
		
		//Select table column
		$this->db->select('*, d.ID_SEKOLAH as ID_SEK');
		$this->db->from('tb_department d'); 
		$this->db->join('tb_master_sekolah s','s.ID_SEKOLAH=d.ID_SEKOLAH');
		$this->db->where('ID_DEPARTMENT',$id_dep);
		$query = $this->db->get();
		return $query;
	}
	
	function update_department($data,$id_dep){
		$this->db->where('ID_DEPARTMENT',$id_dep);
		$this->db->update('tb_department',$data);
	}
	
	function delete_department($id_dep){
		$this->db->where('ID_DEPARTMENT', $id_dep);
		$this->db->delete('tb_department'); 
	}
	
	function getdep_aktif($id_sekolah){
		
		//Select table column
		$this->db->select('d.ID_DEPARTMENT,d.NAMA_DEPARTMENT');
		$this->db->from('tb_master_sekolah s'); 
		$this->db->join('tb_department d','d.ID_DEPARTMENT=s.ID_DEPARTMENT');
		$this->db->where('s.ID_SEKOLAH',$id_sekolah);
		$query = $this->db->get();
		return $query;
	}
	
	//==================================================================
	function get_status(){
		
		$this->db->select('*');
		$this->db->from('tb_master_status'); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('tb_master_status'); 
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_statusID($id_status){
		
		//Select table column
		$this->db->select('*');
		$this->db->from('tb_master_status'); 
		$this->db->where('ID_STATUS',$id_status);
		$query = $this->db->get();
		return $query;
	}
	function insert_status($data){
		$this->db->insert('tb_master_status',$data);
	}
	
	function update_status($data,$id_status){
		$this->db->where('ID_STATUS',$id_status);
		$this->db->update('tb_master_status',$data);
	}
	
	function delete_status($id_status){
		$this->db->where('ID_STATUS', $id_status);
		$this->db->delete('tb_master_status'); 
	}
	
	//==================================================================
	function get_agama(){
		
		$this->db->select('*');
		$this->db->from('tb_master_agama'); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('tb_master_agama'); 
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_agamaID($id_agama){
		
		//Select table column
		$this->db->select('*');
		$this->db->from('tb_master_agama'); 
		$this->db->where('ID_AGAMA',$id_agama);
		$query = $this->db->get();
		return $query;
	}
	function insert_agama($data){
		$this->db->insert('tb_master_agama',$data);
	}
	
	function update_agama($data,$id_agama){
		$this->db->where('ID_AGAMA',$id_agama);
		$this->db->update('tb_master_agama',$data);
	}
	
	function delete_agama($id_agama){
		$this->db->where('ID_AGAMA', $id_agama);
		$this->db->delete('tb_master_agama'); 
	}
	
	//==================================================================
	function get_kondisi(){
		
		$this->db->select('*');
		$this->db->from('tb_master_kondisi'); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('tb_master_kondisi'); 
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_kondisiID($id_kondisi){
		
		//Select table column
		$this->db->select('*');
		$this->db->from('tb_master_kondisi'); 
		$this->db->where('ID_KONDISI',$id_kondisi);
		$query = $this->db->get();
		return $query;
	}
	function insert_kondisi($data){
		$this->db->insert('tb_master_kondisi',$data);
	}
	
	function update_kondisi($data,$id_kondisi){
		$this->db->where('ID_KONDISI',$id_kondisi);
		$this->db->update('tb_master_kondisi',$data);
	}
	
	function delete_kondisi($id_kondisi){
		$this->db->where('ID_KONDISI', $id_kondisi);
		$this->db->delete('tb_master_kondisi'); 
	}
	
	
}

?>
